﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ClarizenGadget.Models;
using Logic;
using Logic.ClarizenObjects;

namespace ClarizenGadget.Controllers
{
    public class IssuesController : Controller
    {
       public ActionResult Create()
       {
           var model = new CreateIssue
           {
               Severity = new QueryComponent().GetListByTypeName("Severity", useCache: true).Select(ge => new Severity(ge))
           };

           return View(model);
       }
        [ValidateInput(false)]
       [HttpPost]
       public ActionResult Create(Issue issue)
       {
           try
           {
               var i = issue.ToGenericEntity();
               new QueryComponent().CreateEntity(i);
               return Json(new GadgetResponse<Issue> { Data = issue, Status = GadgetResponseStatus.Success });
           }
           catch (Exception e)
           {
               return Json(new GadgetResponse<Task> { Status = GadgetResponseStatus.Error, ErrorMessage = e.Message });
           }
       }
    }
}
